function [populatedWindows fracInPopulatedWindows fitFunction] = oldSigmoid (subject, qtyTrials)



%qtyTrials=1000;%20;
sequenceSize=40;


filename=strcat('RAW_',subject);

file=fopen(filename); 
data=fread(file, [4+sequenceSize qtyTrials]);
fclose(file);


%total right
win=0;
trials=1:qtyTrials;
%plot(trials,success);
calibIndices=mean(data(3:2+sequenceSize,:));
calibAnswers=data(sequenceSize+3,:);
calibConfidence=data(sequenceSize+4,:);
   
%hist(mean(noise').*data(sequenceSize+3,:));
 
%plot(calibIndices,calibAnswers,'x');

qtyWindows=20;
step=1;
populatedWindows=[];
fracInPopulatedWindows=[];
winWeights=[];
for winIndex=1:qtyWindows
    
    trialsInWin(winIndex)=0;
    malesInWin(winIndex)=0;
    window=15+(winIndex)*step;
    windows(winIndex)=window;
    
    
    for trial=1:qtyTrials
        if(calibIndices(trial)>= window && calibIndices(trial) < window+step)
            %new line to filter for confidence
            if(calibConfidence(trial)==1)
                
            trialsInWin(winIndex)=trialsInWin(winIndex)+1;
                if(calibAnswers(trial)==1)
                    malesInWin(winIndex)=malesInWin(winIndex)+1;
                end
            end
        end
    end
    
    fracInWin(winIndex)=malesInWin(winIndex)/trialsInWin(winIndex);
    
    if(trialsInWin(winIndex)>0)
       populatedWindows=[populatedWindows window-25.5];
       fracInPopulatedWindows=[fracInPopulatedWindows fracInWin(winIndex)];
       winWeights=[winWeights trialsInWin(winIndex)];
    end
    
end

%trialsInWin
%malesInWin

%windows'
%fracInWin'

%populatedWindows'
%fracInPopulatedWindows'

sigmoidFit = fittype('-1/(1+exp(-a*(x-c)))+1');
fitOpts = fitoptions;

%this was to weight points according to number of cases in bins, but not
%very nice... plus I lose the startpoint.
%fitOpts.Weights = winWeights
%fitOpts.Weights= [50 50 50 50 1 1 1 1]
%fitFunction=fit(populatedWindows',fracInPopulatedWindows', sigmoidFit, fitOpts);  %,'Startpoint',[1 0]
fitFunction=fit(populatedWindows',fracInPopulatedWindows', sigmoidFit, 'Startpoint',[1 0]);


%plot(populatedWindows,fracInPopulatedWindows, 'X');
%hold on;
%plot(fitFunction);
%plot(windows,fracInWin,'o');
%plot(fitFunction)

%hold off;

end

